package com.hoperun.checkcloth.view;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

import com.hoperun.checkcloth.R;

public class SimpleDialog {
    public static void show(Context context, String msg) {

        AlertDialog.Builder dialog = new Builder(context);

        dialog.setTitle(context.getResources().getString(R.string.tips));
        dialog.setMessage(msg);
        dialog.setCancelable(true);

        dialog.setPositiveButton(context.getResources().getString(R.string.confirm), (dialog1, which) -> {
        });

        dialog.show();
    }

    public static void show(Context context, String msg, final OnPositiveClickListener positiveListener) {
        AlertDialog.Builder dialog = new Builder(context);
        dialog.setTitle(context.getResources().getString(R.string.tips));
        dialog.setMessage(msg);
        dialog.setCancelable(true);
        dialog.setPositiveButton(context.getResources().getString(R.string.confirm), (dialog1, which) -> {
            dialog1.dismiss();
            if (positiveListener != null) {
                positiveListener.onPositiveClick();
            }
        });
        dialog.show();
    }

    public static void show(Context context, String msg, final OnNegativeClickListener negativeListener) {

        AlertDialog.Builder dialog = new Builder(context);

        dialog.setTitle(context.getResources().getString(R.string.tips));
        dialog.setMessage(msg);
        dialog.setCancelable(true);
        dialog.setNegativeButton(context.getResources().getString(R.string.cancel), (dialog1, which) -> {
            if (negativeListener != null) {
                negativeListener.onNegativeClick();
            }
        });


        dialog.show();
    }

    public static void show(Context context, String msg, final OnNegativeClickListener negativeListener, final OnPositiveClickListener positiveListener) {

        AlertDialog.Builder dialog = new Builder(context);

        dialog.setTitle(context.getResources().getString(R.string.tips));
        dialog.setMessage(msg);
        dialog.setCancelable(true);
        dialog.setNegativeButton(context.getResources().getString(R.string.cancel), (dialog1, which) -> {
            if (negativeListener != null) {
                negativeListener.onNegativeClick();
            }
        });
        dialog.setPositiveButton(context.getResources().getString(R.string.confirm), (dialog12, which) -> {
            if (positiveListener != null) {
                positiveListener.onPositiveClick();
            }

        });

        dialog.show();
    }


    public static void forceShow(Context context, String msg) {

        AlertDialog.Builder dialog = new Builder(context);

        dialog.setTitle(context.getResources().getString(R.string.tips));
        dialog.setMessage(msg);
        dialog.setCancelable(false);

        dialog.setPositiveButton(context.getResources().getString(R.string.confirm), (dialog1, which) -> {
        });

        dialog.show();
    }

    public static void forceShow(Context context, String msg, final OnPositiveClickListener positiveListener) {

        AlertDialog.Builder dialog = new Builder(context);

        dialog.setTitle(context.getResources().getString(R.string.tips));
        dialog.setMessage(msg);
        dialog.setCancelable(false);

        dialog.setPositiveButton(context.getResources().getString(R.string.confirm), (dialog1, which) -> {
            dialog1.dismiss();
            if (positiveListener != null) {
                positiveListener.onPositiveClick();
            }
        });

        dialog.show();
    }

    public static void forceShow(Context context, String msg, final OnNegativeClickListener negativeListener) {

        AlertDialog.Builder dialog = new Builder(context);

        dialog.setTitle(context.getResources().getString(R.string.tips));
        dialog.setMessage(msg);
        dialog.setCancelable(false);
        dialog.setNegativeButton(context.getResources().getString(R.string.cancel), (dialog1, which) -> {
            if (negativeListener != null) {
                negativeListener.onNegativeClick();
            }
        });

        dialog.show();
    }

    public static void forceShow(Context context, String msg, final OnNegativeClickListener negativeListener, final OnPositiveClickListener positiveListener) {
        AlertDialog.Builder dialog = new Builder(context);

        dialog.setTitle(context.getResources().getString(R.string.tips));
        dialog.setMessage(msg);
        dialog.setCancelable(false);
        dialog.setNegativeButton(context.getResources().getString(R.string.cancel), (dialog1, which) -> {
            if (negativeListener != null) {
                negativeListener.onNegativeClick();
            }
        });
        dialog.setPositiveButton(context.getResources().getString(R.string.confirm), (dialog12, which) -> {
            if (positiveListener != null) {
                positiveListener.onPositiveClick();
            }

        });

        dialog.show();
    }


    public interface OnPositiveClickListener {
        void onPositiveClick();
    }

    public interface OnNegativeClickListener {
        void onNegativeClick();
    }

}

